<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>学校通知</title>
	<link rel="stylesheet" href="../css/common2.css">
	<style>
		.search_img {
			position: absolute;
			right: 3%;
		}

		.photo {
			width: 50px;
			height: 50px;
		}

		.add {
			width: 140px;
			background-image: url(../image/add_long.png);
		}

		td img {
			max-width: 50px;
			max-height: 50px;
		}
	</style>
</head>

<body>
	<div style="margin-top: 30px;"></div>
	<div id="vue-root">
		<div v-if="able.add" class="add">
			<a href="school_notice_item.html" style="color: white">添加学校公告</a>
		</div>
		<div class="refresh" onclick="location.reload()">刷新</div>
		<select class="search" v-model="search.receiver">
			<option :value="undefined">请选择面向对象</option>
			<option :value="0">面向全校师生</option>
			<option :value="1">面向全体教师</option>
			<option :value="2">面向全体学生</option>
		</select>
		<img src="../image/search.png" height="35" width="35" class="search_img" @click="getData0">

		<div class="table ">
			<table class="table_top">
				<thead>
					<tr>
						<th class="one">
							<input type="checkbox" class="check-box" v-model="all">序号
						</th>
						<th>标题</th>
						<th>时间</th>
						<th>发布者</th>

						<th class="four">内容</th>
						<th>面向对象</th>
						<th>已读人数/发布总人数</th>
						<th>编辑/删除</th>
					</tr>
				</thead>
				<tbody id="list">
					<tr v-for="(notice,index) in list" :key="notice.id">
						<td class="one">
							<input type="checkbox" class="check-box" v-model="notice.checked">
							<span v-text="index+1"></span>
						</td>
						<td v-text="notice.title"></td>
						<td v-text="notice.time"></td>
						<td v-text="notice.publisher"></td>

						<td class="four" v-text="getText(notice.content)"></td>
						<td v-text="['面向全体师生','面向全体教师','面向全体学生'][notice.receiver]"></td>
						<td v-text="notice.read+'/'+notice.total"></td>
						<td>
							<div class="option">
								<div v-if="able.edit" class="edit-icon option-icon" @click="edit(notice.id)"
									style="position: absolute; left: 20%; top: 30%;">
									<img class="img" src="../image/edit.png" height="20" width="20"
										onmouseover="this.src='../image/edit_light.png'"
										onmouseout="this.src='../image/edit.png'" />
								</div>
								<div v-if="able.del" class="delete-icon option-icon" @click="del([notice.id])"
									style="right: 20%; top:30%;position: absolute;">
									<img class="img" src="../image/delete.png" height="20" width="20"
										onmouseover="this.src='../image/delete_light.png'"
										onmouseout="this.src='../image/delete.png'" />
								</div>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<br>
		<div class="delete" @click="batchDelete" v-if="able.del">批量删除</div>
		<ul class="pagination" v-if="pages>1">
			<li>
				<a v-if="pageNum!=1" @click="pageNum=1">«</a>
				<a class="pages-jump" v-if="pageNum!=1" @click="pageNum--">‹</a>
				<a v-text="pageNum"></a>
				<a class="pages-jump" v-if="pageNum!=pages" @click="pageNum++">›</a>
				<a v-if="pageNum!=pages" @click="pageNum=pages">»</a>
			</li>
		</ul>

	</div>
	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>

	<script src="/js/common.js"></script>
	<script src="/js/list.js"></script>
	<script src="/js/auth_util.js"></script>

	<script>
		var app = new Vue(merge({
			data: {
				urls: {
					del: '/pc/notice/del'
				}
			},
			created: function () {
				var schoolId = top_params().id;
				if (!schoolId) throw 'no school id';
				this.urls.list = '/pc/notice/list/' + schoolId;
				this.getData();
				abled('notice', this);
			},
			methods: {
				edit: function (id) {
					location.href = "school_notice_item.html?id=" + id;
				},
				getImg: function (notice) {
					if (!notice.pic) return null;
					return '/static/' + notice.schoolId + '/notice/' + notice.pic;
				},
				getText: function (html) {
					var b = document.createElement('div');
					b.innerHTML = html;
					var a = b.innerText;
					b.remove();
					if (a && a.length > 150)
						a = a.substr(0, 150) + '...';
					return a;
				},
			}
		}));
	</script>
</body>

</html>